﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nage.Algorithms;
using Nage.Algorithms.Solution;
using Nage.Algorithms.RandomGenerators;
using Utils.Logger;

namespace Nage.Examples.Rastrigin.Solution
{
    public class CoordinatesFactory : ISolutionFactory<Coordinates>
    {
        #region Private fields
        private Random _random;
        private double _minX;
        private double _minY;
        private double _maxX;
        private double _maxY;
        #endregion

        #region Constructor
        public CoordinatesFactory()
            : this(-5, -5, 5, 5)
        {
        }

        public CoordinatesFactory(double minX, double minY, double maxX, double maxY)
        {
            CLogger.LogTrace("Creating CoordinatesFactory.");
            this._random = new Random();
            this._minX = minX;
            this._minY = minY;
            this._maxX = maxX;
            this._maxY = maxY; 
        }
        #endregion

        #region CreateEmptySolution
        public Coordinates CreateEmptySolution()
        {
            CLogger.LogTrace("CoordinatesFactory -> CreateEmptySolution");
            return new Coordinates();
        } 
        #endregion

        #region CreateInitializedSolution
        public Coordinates CreateInitializedSolution()
        {
            CLogger.LogTrace("CoordinatesFactory -> CreateInitializedSolution");
            double x = Rng.GetInstance().GetDouble(_minX, _maxX);
            double y = Rng.GetInstance().GetDouble(_minY, _maxY);
            return new Coordinates(x, y);
        } 
        #endregion

        #region Copy
        public Coordinates Copy(Coordinates source)
        {
            CLogger.LogTrace("CoordinatesFactory -> Copy");
            return new Coordinates(source.X, source.Y);
        } 
        #endregion
    }
}
